package com.hazardSoft.eStore.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hazardSoft.eStore.common.exception.SystemException;
import com.hazardSoft.eStore.entities.City;
import com.hazardSoft.eStore.entities.Role;
import com.hazardSoft.eStore.entities.User;
import com.hazardSoft.eStore.integration.UsersDelegate;

/**
 * Servlet implementation class Prueba
 */
public class Prueba extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//super.doGet(request, response);
		doAll(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
//		super.doPost(request, response);
		doAll(request, response);
	}

	private void doAll(HttpServletRequest request, HttpServletResponse response) {
		User user = new User();
		user.setAddress("direccion");
		user.setId(0);
		
		City city = new City(1);
		user.setCity(city);
		user.setLogin("wf");
		user.setName("felipe");
		user.setPassword("54321");
		
		Role role = new Role(3);
		user.setRole(role);
		user.setSocialnumber(12345L);
		user.setTelephone(12345);
		user.setEmail("wf@h.com");
				
		try {
			UsersDelegate usersDelegate = new UsersDelegate();
			usersDelegate.insertUser(user);
//			System.out.println(usersDelegate.authenticateUser(user).getName());
//			for (User user2 : usersDelegate.listUsers()) {
//				System.out.println(user2.getName());
//			}
//			usersDelegate.removeUser(user);
//			usersDelegate.updateUser(user);
		} catch (SystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}